import React, { Component } from 'react'
import Onelist from "./oneList";
import store from "../../store/index";
import { withRouter } from 'react-router';

class bigAllList extends Component {
    constructor(props){
        super(props)
        this.state={
            listInfo:"",
            kind:store.getState().kindreducer.kind
        }
    }
    componentDidMount(){
        console.log(store.getState().indexReducer)
        this.setState({
            kind:store.getState().kindreducer.kind
        })
        store.subscribe(()=>{
            this.setState({
                kind:store.getState().kindreducer.kind
            },()=>{
                console.log(this.state.kind);
                // alert(1);
                jianting();
            })
        })
        
        let jianting = ()=>{
            let i = 0;
            let newarr=[];
            if(store.getState().indexReducer.state){
                store.getState().indexReducer.state.forEach((item,index)=>{
                    if(item.kind.split(",")[1] == this.state.kind){
                        newarr.push(item);
                    }else{
                    }
                    this.setState({
                        listInfo:newarr
                    },()=>{
                        console.log(this.state.listInfo)
                    })
                    // console.log(item.kind.split(",")[1])
                })
            }else{
                console.log("无数据");
            }
        }
        jianting()
    }
    componentDidUpdate(){
        console.log(2)
        console.log(this.props.kind)
    }
    getListInfo(){
        return this.state.listInfo.map((item,index)=>{
            return (
                <div className="onelist">
                    <Onelist info={item} key={item.id}></Onelist>
                </div>
            )
        })
    }
    render() {
        return (
            <div>
                {this.state.listInfo?this.getListInfo():"没有数据"}
            </div>
        )
    }
}
export default withRouter(bigAllList)